package com.leetcode;

import org.junit.Test;

/**
 * Created by Z-hong on 2022/9/29.
 */

public class LeetCode面试0109 {
    public boolean isFlipedString(String s1, String s2) {
        if (s1.equals(s2)) return true;
        if (s1.length() != s2.length()) return false;
        boolean flag = false;
        char[] c1 = s1.toCharArray();
        char[] c2 = s2.toCharArray();
        for (int i = 0; i < c2.length; i++) {
            if (c2[i] == c1[0]) {
                int z = 1;
                flag = true;
                for (int j = i + 1; j < c2.length; j++) {
                    if (c2[j] != c1[z++]) {
                        flag = false;
                        break;
                    }

                }
                for (int j = 0; j < i; j++) {
                    if (c2[j] != c1[z++]){
                        flag = false;
                        break;
                    }
                }
                if (flag){return flag;}
            }
        }
        return flag;
    }

    //力扣最优解
    public boolean isFlipedString1(String s1, String s2) {
        return s1.length() == s2.length() && (s1 + s1).contains(s2);
    }

    @Test
    public void test() {
        String s1 = "waterbottle";
        String s2 = "erbottlewat";
        System.out.println(isFlipedString(s1, s2));
    }
}
